<template>
  <div>
    api result test <button @click="btnclick">test</button>
    <ul>
      <li v-for="(item, key) in apiList" :key="key">
        <button @click="apitest(key, item)">apiTest</button> {{ key }}
      </li>
    </ul>
    <h3>Input</h3>
    <p>
      {{ sendApiPara }}
    </p>
    <hr />
    <h3>Output</h3>
    <hr />
    <p>
      {{ apiRes }}
    </p>
  </div>
</template>

<script>
import {
  fetchAlarmHis,
  fetchList,
  fetchAlarmByID,
  fetchPv,
  createAlarm,
  updateAlarm,
  removeRecord,
} from "@/api/alarm.js";
export default {
  data() {
    return {
      test: "wo shi test",
      apiPara: {
        fetchAlarmHis: "",
        fetchList: "",
        fetchAlarmByID: "2",
        fetchPv: "",
        createAlarm: {
          genTime: "2021/03/21 11:00:00",
          name: "Caps for Voice high",
          source: "DV",
          status: "Open",
          handleBy: "",
          progress: "",
          record: "Caps for Voice high_20210321110000.docx",
        },
        updateAlarm: {
          alarmid: 29,
          name: "xxxxxxxxxxxxxxx",
          source: "DV",
          status: "Open",
          handleBy: "xxx",
          progress: "",
          record: "Caps for Voice high_20210321110000.docx",
        },
        removeRecord: 29,
      },
      apiList: {
        fetchAlarmHis: fetchAlarmHis,
        fetchList: fetchList,
        fetchAlarmByID: fetchAlarmByID,
        fetchPv: fetchPv,
        createAlarm: createAlarm,
        updateAlarm: updateAlarm,
        removeRecord: removeRecord,
      },
      apiRes: {},
      sendApiPara: "",
    };
  },
  methods: {
    btnclick() {
      // fetchAlarmHis().then((res) => (this.apiRes = res));
      console.log("test :>> ", this.apiList[1]);
    },
    apitest(apiName, apiBody) {
      console.log("start test API :>> ", apiName);
      // get the parameter
      // console.log("this.apiPara :>> ", this.apiPara);
      this.sendApiPara = this.apiPara[apiName];
      console.log("API parameter:>> ", this.sendApiPara);
      // execute api
      if (this.sendApiPara === "") {
        apiBody().then((res) => (this.apiRes = res));
      } else {
        apiBody(this.sendApiPara).then((res) => (this.apiRes = res));
      }
    },
  },
};
</script>

<style>
</style>